package com.zxl.designpattern.structure.adapter;

/**
 * @author zxl
 * @version 1.0
 * @description 支付适配器，将旧的支付系统适配到新的支付系统中
 * @date 2025/6/1 17:16
 */
public class PaymentObjectAdapter implements Payment{

    // 新的支付系统持有旧的支付系统的对象
    private final LegacyPaymentSystem legacyPaymentSystem;

    public PaymentObjectAdapter(LegacyPaymentSystem legacyPaymentSystem) {
        this.legacyPaymentSystem = legacyPaymentSystem;
    }
    @Override
    public void processPayment(double amount, int paymentType) {
        if (paymentType == 1){
            legacyPaymentSystem.makePayment(amount);
        }else {
            makePayment(amount, paymentType);
        }
    }

    /**
     * 新的支付系统
     * @param amount
     * @param paymentType
     */
    private void makePayment(double amount, int paymentType) {
        if (paymentType == 2){
            System.out.print("处理支付宝支付");
        }else if (paymentType == 3){
            System.out.print("处理微信支付");
        }else {
            System.out.print("不支持的支付类型");
        }
        System.out.printf(" 处理金额%.2f%n", amount);
    }

    /****************** 此类是为了实现类适配器，请当下面的不存在，实现仅为了不报错 **********************/
    @Override
    public void processCreditCard(double amount) {

    }

    @Override
    public void processDebitCard(double amount) {

    }

    @Override
    public void processWeixin(double amount) {

    }

    @Override
    public void processAlipay(double amount) {

    }
}
